<template>
    <async-modal initHeight="500px" initWidth="900px" title="风控提示" @update:visible="cancel">
        <template #modalBody>
            <el-table class="hasBorderBottom" :data="props.secondConfirmResult" border :span-method="mergeRiskCellsMethod">
                <el-table-column min-width="200" prop="title" label="风控项目" show-overflow-tooltip/>
                <el-table-column min-width="600" prop="message" label="触发原因" show-overflow-tooltip/>
            </el-table>
        </template>
        <template #modalFoot>
            <div class="event-button">
                <el-button type="primary" @click="onSubmit">确定</el-button>
                <el-button @click="cancel">取消</el-button>            
            </div>
        </template> 
    </async-modal>
</template>

<script setup lang="ts">
import AsyncModal from '@/components/Modal/index.vue';

let $emit = defineEmits(['closeDig','secondConfirm']);

const props = defineProps<{
    secondConfirmResult: any[];
}>();
const cancel = ()=>{
    $emit('closeDig');
}
const onSubmit = async () => {
    $emit('secondConfirm');
}
const mergeRiskCellsMethod = ({ row, rowIndex, column }: any) => {
    let data = props.secondConfirmResult;
    // 只对title列进行合并
    if (column.property === 'title') { // title列
        const cellValue = row.title;
        if (cellValue === null || cellValue === undefined) {
            return { rowspan: 1, colspan: 1 };
        }

        let rowspan = 1;
        let currentIndex = rowIndex;

        // 向上查找相同值的行
        while (currentIndex > 0) {
            const prevRow = data[currentIndex - 1];
            if (prevRow && prevRow.title === cellValue) {
                currentIndex--;
            } else {
                break;
            }
        }

        // 如果当前行不是第一个相同值的行，则返回 rowspan: 0, colspan: 0 隐藏单元格
        if (rowIndex !== currentIndex) {
            return { rowspan: 0, colspan: 0 };
        }

        // 向下计算相同值的行数
        while (currentIndex + rowspan < data.length) {
            const nextRow = data[currentIndex + rowspan];
            if (nextRow && nextRow.title === cellValue) {
                rowspan++;
            } else {
                break;
            }
        }
        return { rowspan, colspan: 1 };
    }
    return { rowspan: 1, colspan: 1 };
};
onMounted(()=>{
})
</script>

<style scoped lang="scss">
</style>
